package cn.edu.zjut.mina.repository;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;


import org.springframework.data.repository.query.Param;

import cn.edu.zjut.mina.po.TotalGameResult;

public interface TotalGameResultRepository extends JpaRepository<TotalGameResult, Integer>, JpaSpecificationExecutor <TotalGameResult> {
	TotalGameResult findByTotalGameResultId(Integer totalGameResultId);
//	@Query(value = "select TotalGameResult* from TotalGameResult t, EveryGameResult e, PlayerBattleInfo p where  t.everyGameResultId=e.everyGameResultId and e.playerBattleInfoId=p.playerBattleInfoId and p.userId=?1",
//			countQuery = "SELECT count(*) from TotalGameResult t, EveryGameResult e, PlayerBattleInfo p where  t.everyGameResultId=e.everyGameResultId and e.playerBattleInfoId=p.playerBattleInfoId and p.userId=?1",nativeQuery = true)

	
//	@Query("select t from PlayerBattleInfo u join u.everyGameResult e join e.totalGameResult t where u.userId = :userId")
//	List<TotalGameResult> findTotalGameResultByUserId(@Param("userId")String userId);
	
	/*
	 * 多表关联条件分页查询的例子  这个接口是查询非强制退出的逻辑
	 */
	@Query("select t from PlayerBattleInfo u join u.everyGameResult e join e.totalGameResult t where u.userId = :userId and t.constraintQuitRoom = 0")
	Page<TotalGameResult> findTotalGameResultByUserId(@Param("userId")String userId, Pageable pageable);
	
}
